#include "auto_door.h"

namespace application {
namespace auto_door {

AutoDoor::AutoDoor(int doorId, const QString& point1, const QString& point2,
                   std::shared_ptr<kernel::ILogger> logger, QObject* parent)
    : QObject(parent)
    , m_doorId(doorId)
    , m_point1(point1)
    , m_point2(point2)
    , m_logger(logger)
{
}

void AutoDoor::open()
{
    if (m_state == DoorState::Open || m_state == DoorState::Opening) {
        return;
    }

    m_state = DoorState::Opening;
    emit stateChanged(m_state);

    if (m_logger) {
        m_logger->info(QString("自动门 %1 正在打开").arg(m_doorId));
    }

    // 模拟门打开过程（实际应该与硬件通信）
    m_state = DoorState::Open;
    emit stateChanged(m_state);
    emit doorOpened();

    if (m_logger) {
        m_logger->info(QString("自动门 %1 已打开").arg(m_doorId));
    }
}

void AutoDoor::close()
{
    if (m_state == DoorState::Closed || m_state == DoorState::Closing) {
        return;
    }

    m_state = DoorState::Closing;
    emit stateChanged(m_state);

    if (m_logger) {
        m_logger->info(QString("自动门 %1 正在关闭").arg(m_doorId));
    }

    // 模拟门关闭过程
    m_state = DoorState::Closed;
    emit stateChanged(m_state);
    emit doorClosed();

    if (m_logger) {
        m_logger->info(QString("自动门 %1 已关闭").arg(m_doorId));
    }
}

} // namespace auto_door
} // namespace application
